﻿
namespace Patterns4Net.ArchitectureExplorer.Diagram
{
    using System.Linq;
    using System.Collections.Generic;
    using Patterns4Net.Attributes;

    public class TypeInfo : DiagramElement
    {
        private IList<PatternInfo> patterns = new List<PatternInfo>();

        public TypeInfo(string name, IEnumerable<PropertyInfo> properties, IEnumerable<MethodInfo> methods)
            : base(name)
        {
            this.Properties = properties.ToArray();
            this.Methods = methods.ToArray();

            foreach (var methodInfo in this.Methods)
            {
                methodInfo.Parent = this;
            }

            foreach (var propertyInfo in this.Properties)
            {
                propertyInfo.Parent = this;
            }

            this.AbstractionLevel = AbstractionLevel.Normal;
        }

        public IEnumerable<PropertyInfo> Properties { get; private set; }

        public IEnumerable<MethodInfo> Methods { get; private set; }

        public AbstractionLevel AbstractionLevel { get; set; }

        public IEnumerable<PatternInfo> Patterns
        {
            get { return this.patterns; }
        }

        public void AddPattern(PatternInfo pattern)
        {
            this.patterns.Add(pattern);
        }

        public override string ToString()
        {
            return this.Name;
        }

        public override void Accept(DiagramVisitor visitor)
        {
            visitor.Visit(this);

            foreach (var methodInfo in this.Methods)
            {
                methodInfo.Accept(visitor);
            }

            foreach (var propertyInfo in this.Properties)
            {
                propertyInfo.Accept(visitor);
            }
        }
    }
}
